package com.example.lib_router_compiler;

//@AutoService(Processor.class)
//public class PathProcessor extends AbstractProcessor {
//    Filer filer;
//
//    @Override
//    public synchronized void init(ProcessingEnvironment processingEnv) {
//        super.init(processingEnv);
//        filer = processingEnv.getFiler();
//    }
//
//    @Override
//    public Set<String> getSupportedAnnotationTypes() {
//        Set<String> annotations = new HashSet<>();
//        annotations.add(RouterPath.class.getCanonicalName());
//        return annotations;
//    }
//
//    @Override
//    public boolean process(Set<? extends TypeElement> annotations, RoundEnvironment roundEnv) {
//        Set<? extends Element> elements = roundEnv.getElementsAnnotatedWith(RouterPath.class);
//        Map<String, String> map = new HashMap<>();
//        for (Element element : elements) {
//            TypeElement typeElement = (TypeElement) element;
//            String activityName = typeElement.getQualifiedName().toString();
//            System.out.println("----------activityName:" + activityName);
//            String key = typeElement.getAnnotation(RouterPath.class).value();
//            System.out.println("------key:" + key);
//            map.put(key, activityName);
//        }
//        if (map.size() > 0) {
//            String utilsName = "AppRouterInit";
//            Writer writer = null;
//            try {
//                JavaFileObject sourceFile = filer.createSourceFile("cn.yzwill.router.generate." + utilsName);
//                writer = sourceFile.openWriter();
//                StringBuilder stringBuilder = new StringBuilder();
//                stringBuilder.append("package cn.yzwill.router.generate;\n");
//                stringBuilder.append("import com.example.lib_router.IRouterComponent;\n");
//                stringBuilder.append("import com.example.lib_router.Router;\n");
//                stringBuilder.append("public class ")
//                        .append(utilsName)
//                        .append(" implements IRouterComponent {\n");
//
//                stringBuilder.append("@Override\n");
//                stringBuilder.append("public void init() {\n");
//
//                Iterator<String> iterator = map.keySet().iterator();
//
//                while (iterator.hasNext()) {
//                    String key = iterator.next();
//                    String activityName = map.get(key);
//                    stringBuilder.append(" Router.getInstance().registerRoute(\"")
//                            .append(key).append("\",\"")
//                            .append(activityName)
//                            .append("\");");
//                }
//                stringBuilder.append("}\n}");
//                writer.write(stringBuilder.toString());
//                writer.close();
//            } catch (IOException e) {
//                e.printStackTrace();
//            }
//        }
//        return false;
//    }
//}
